package top.zhangjianyong.blog.manage.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.blog.annotation.Permission;
import top.zhangjianyong.blog.enums.RoleKeys;
import top.zhangjianyong.blog.params.user.UserSkillDeleteParam;
import top.zhangjianyong.blog.params.user.UserSkillListParam;
import top.zhangjianyong.blog.params.user.UserSkillSaveOrUpdateParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.UserSkillService;

/**
 * 用户技能管理控制器
 *
 * @author zhangjianyong
 * @since 2024/7/1
 */
@RestController
@RequestMapping("/manage/user-skill")
public class UserSkillController {

  @Autowired private UserSkillService userSkillService;

  /** 获取用户技能列表 */
  @PostMapping("/list")
  @Permission(roles = {RoleKeys.ADMIN})
  public ApiResponse list(@RequestBody @Validated UserSkillListParam param) {
    return userSkillService.listByUserId(param.userId());
  }

  /** 保存或更新用户技能 */
  @PostMapping("/saveOrUpdate")
  @Permission(roles = {RoleKeys.ADMIN})
  public ApiResponse saveOrUpdate(@RequestBody @Validated UserSkillSaveOrUpdateParam param) {
    return userSkillService.saveOrUpdate(param);
  }

  /** 删除用户技能 */
  @PostMapping("/delete")
  @Permission(roles = {RoleKeys.ADMIN})
  public ApiResponse delete(@RequestBody @Validated UserSkillDeleteParam param) {
    return userSkillService.deleteById(param.id());
  }

  /** 批量更新排序 */
  @PostMapping("/updateSortOrder")
  @Permission(roles = {RoleKeys.ADMIN})
  public ApiResponse updateSortOrder(
      @RequestBody @Validated List<UserSkillSaveOrUpdateParam> params) {
    return userSkillService.updateSortOrder(params);
  }
}
